package com.heima.wemedia.controller.v1;

import com.heima.model.admin.dtos.AdminChannelPageDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsChannelDto;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {
    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 自媒体端文章频道查询
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult WemediaList(){
        return ResponseResult.okResult(wmChannelService.findAll());
    }

    /**
     * 管理端文章频道查询
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult AdminList(@RequestBody AdminChannelPageDto dto){
        return wmChannelService.AdminPageList(dto);
    }

    /**
     * 新增文章频道
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody WmNewsChannelDto dto){
        return wmChannelService.saveChannel(dto);
    }

    /**
     * 修改文章频道状态
     * @param dto
     * @return
     */
    @PostMapping("update")
    public ResponseResult update(@RequestBody WmNewsChannelDto dto){
        return wmChannelService.updateChannel(dto);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable Integer id){
        return wmChannelService.del(id);
    }
}
